<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function testCode(n){
            var arr = []
            
            for (var i = 0; i < n ; i++ )
            {
                var num = parseInt(Math.random()*10)
                arr.push(num)
            }
            var str = arr.join("")
            console.log(str)
        }
        testCode(6)


        function testCode1(n){
            var arr = []
            for(var i = 0; i<n ; i++)
            {
                var num = parseInt(Math.random()*100)
                if(num>=0&&num<=9){
                    arr.push(num)
                }else if(num>=97&&num<=122||num>=65&&num<90)
                {
                    arr.push(String.fromCharCode(num))
                }else
                {
                    i--
                }
            }
            return arr.join("")
        }
        testCode1(6)

        function btnClick(){
            var oDiv = document.getElementById("div1")
            //alert(oDiv)
            oDiv.innerHTML = testCode1(6);
        }
    </script>
</head>
<body>
    <div id = "div1">0000000</div>

        <button onclick='btnClick();'>获取验证码</button>
    </div>
    
</body>
</html>